package com.giga.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.giga.entity.User;
import com.giga.mapper.UserMapper;
import com.giga.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insertUser(User user) {
        user.setCreateTime(new Date());
        return userMapper.insert(user);
    }

    @Override
    public List<User> selectAll() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("name", "email");
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public User selectByName(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("name", user.getName()).or().eq("email", user.getEmail());
        queryWrapper.eq("email", user.getEmail());
        return userMapper.selectOne(queryWrapper);
    }

}
